<template>
	<view class="layout">
		<uni-header :leftIcon="true" :title="'活动满意度'"></uni-header>
		<view class="content">
			<view class="evaluate">
				<view class="evaluate-list">
					<text class="title-text">满意度</text>
				</view>
				<view class="evaluate-list">
					<uni-data-checkbox v-model="satisfaction" :localdata="sexs" />
				</view>
			</view>
			<view class="evaluate">
				<view class="evaluate-list">
					<uni-easyinput v-model="suggest" type="textarea" placeholder="请输入意见" />
				</view>
			</view>
			<u-button type="primary" @click="saveDegree">保存</u-button>
		</view>
	</view>
</template>

<script>
	import {
		saveClassSatisfaction,
		getClassSatisfaction,
		getEmulateSatisfaction,
		saveEmulateSatisfaction
	} from "@/api/home"
	export default {
		data() {
			return {
				deviceId: this.$store.state.user.deviceId,
				sexs: [{
					text: '非常满意',
					value: 1
				}, {
					text: '满意',
					value: 2
				}, {
					text: '一般',
					value: 3
				}, {
					text: '不满意',
					value: 4
				}],
				satisfaction_id: "",
				satisfaction: "",
				suggest: "",
			}
		},
		onLoad(option) {
			this.activeId = option.activeId;
			this.type = option.type;
			if (this.type == "class") {
				this.getClassDegree();
			} else if (this.type == "emulate") {
				this.getEmulateDegreee();
			}
		},
		methods: {
			//获取听评课满意度数据
			getClassDegree() {
				getClassSatisfaction({
					activityId: this.activeId,
					deviceId: this.deviceId
				}).then(res => {
					this.satisfaction_id = res.satisfaction_id
					this.satisfaction = res.satisfaction
					this.suggest = res.suggest
				})
			},
			//获取观摩课下满意度数据
			getEmulateDegreee() {
				getEmulateSatisfaction({
					activityId: this.activeId,
					deviceId: this.deviceId
				}).then(res => {
					this.satisfaction_id = res.satisfaction_id
					this.satisfaction = res.satisfaction
					this.suggest = res.suggest
				})
			},
			//保存满意度数据
			saveDegree() {
				if (this.type == "class") {
					this.addClassDegree();
				} else if (this.type == "emulate") {
					this.addEmulateDegree();
				}
			},
			//听评课下满意度数据
			addClassDegree() {
				let params = {
					satisfaction_id: this.satisfaction_id,
					satisfaction: this.satisfaction,
					suggest: this.suggest,
					activityId: this.activeId,
					deviceId: this.$store.state.user.deviceId,
				}
				saveClassSatisfaction(params).then(res => {
					if (res.status == 0) {
						this.$modal.showToast('保存成功')
					}
				})
			},
			//观摩课下满意度数据
			addEmulateDegree() {
				let params = {
					satisfaction_id: this.satisfaction_id,
					satisfaction: this.satisfaction,
					suggest: this.suggest,
					activityId: this.activeId,
					deviceId: this.$store.state.user.deviceId
				}
				saveEmulateSatisfaction(params).then(res => {
					if (res.status == 0) {
						this.$modal.showToast('保存成功')
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.layout {
		.content {
			.evaluate {
				background: #fff;
				margin-bottom: 15px;

				.evaluate-list {
					display: flex;
					justify-content: space-between;
					align-items: center;
					border-bottom: 1px solid #ddd;
					padding: 10px 15px;

					.left-title {
						width: 20vw;
					}

					.right {
						width: 80vw;
						text-align: right;
					}
				}
			}
		}
	}
</style>